﻿package com.bizmlib.framework.flashapp
{
	import com.bizmlib.framework.abstract.AbstractEngine;
	import com.bizmlib.framework.abstract.mvc.*;
	import com.bizmlib.framework.flashapp.mvc.*;
	
	
	class FlashAppEngineCore extends AbstractEngine
	{
		
		/**
		 * Overrden methods of AbstractEngine class for createing mvc instances.
		 */
		/**/
		override protected function createModel(model:AbstractModel):void
		{
			//trace(this + ".createModel(" + arguments + ")");
			//trace("model=" + model);
			
			if(!model)
			{
				model = new FlashAppModel();
			}
			else if(!(model is FlashAppModel))
			{
				throw new Error(this + ".createModel failed: model parameter needs to be an instance of FlashAppModel or any of its subclass. It's true that method's definition requires it to be an AbstractModel, but that's because of the as3 specificity of inheritance and overriding. Still it has to be compatible with FlashAppModel type.");
			}
			
			super.createModel(model);
		}
		/**/
		override protected function createView(view:AbstractView):void
		{
			//trace(this + ".createView(" + arguments + ")");
			
			if(!view)
			{
				view = new FlashAppView(model as FlashAppModel);
			}
			else if(!(view is FlashAppView))
			{
				throw new Error(this + ".createView failed: view parameter needs to be an instance of FlashAppView or any of its subclass. It's true that method's definition requires it to be an AbstractView, but that's because of the as3 specificity of inheritance and overriding. Still it has to be compatible with FlashAppView type.");
			}
			
			super.createView(view);
		}
		override protected function createController(controller:AbstractController):void
		{
			//trace(this + ".createController(" + arguments + ")");
			
			if(!controller)
			{
				controller = new FlashAppController(view as FlashAppView);
			}
			else if(!(controller is FlashAppController))
			{
				throw new Error(this + ".createController failed: controller parameter needs to be an instance of FlashAppController or any of its subclass. It's true that method's definition requires it to be an AbstractController, but that's because of the as3 specificity of inheritance and overriding. Still it has to be compatible with FlashAppController type.");
			}
			
			super.createController(controller);
		}
	}
}